﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;

namespace WindowsFormsApplication1.wtyczki
{
    public static class addRGB
    {
        public static Bitmap addColor(Bitmap bm)
        {
            if (bm == null)
                return null;

            myRGB tmpColor = new myRGB();
            using (addRGBform form2 = new addRGBform())
            {
                form2.ShowDialog();
                tmpColor = form2.TheValue;
            }

            int red, green, blue;
            int getpxbm;

            for (int x = 0; x < bm.Width; x++)
            {
                for (int y = 0; y < bm.Height; y++)
                {
                    getpxbm = bm.GetPixel(x, y).R + tmpColor.R;

                    if (getpxbm > 255)
                        red = 255;
                    else if (getpxbm < 0)
                        red = 0;
                    else
                        red = getpxbm;

                    getpxbm = bm.GetPixel(x, y).G + tmpColor.G;
                    if (getpxbm > 255)
                        green = 255;
                    else if (getpxbm < 0)
                        green = 0;
                    else
                        green = getpxbm;

                    getpxbm = bm.GetPixel(x, y).B + tmpColor.B;

                    if (getpxbm > 255)
                        blue = 255;
                    else if (getpxbm < 0)
                        blue = 0;
                    else
                        blue = getpxbm;

                    bm.SetPixel(x, y, Color.FromArgb(red, green, blue));
                }
            }
            return bm;
        }
    }
}
